package cn.itcast.user.web;

import cn.itcast.user.config.PatternProperties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private int port;

    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {

        User user = userService.queryById(id);
        user.setAddress(""+this.port);
        return user;
    }
    @PostMapping("save")
    public String save(@RequestBody User user){
        System.out.println(user);
        return "保存成功";
    }
    @Autowired
    private PatternProperties p;

    @GetMapping("now")
    public String now(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(p.getDateformat()));
    }
    @GetMapping("prop")
    public PatternProperties prop(){
        return p;
    }
}
